using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace StudentManagementApplication
{
    public partial class FrmMain : Form
    {
        public string sRole;
        public string sPersonID;
        public string sLoginID;

        public FrmMain()
        {
            InitializeComponent();
        }

        private void ShowFormLogin()
        {
            FrmLogin frmLogin = new FrmLogin();
            frmLogin.frmMain = this;
            frmLogin.StartPosition = FormStartPosition.CenterParent;
            frmLogin.ShowDialog();
            tsmiLogin.Enabled = false;
            InitializeMenuOfApplication();
        }

        private void ShowLogout()
        {
            if (MessageBox.Show("You want to log out the system?", "Information", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
            {
                EnableMenuOfApplication();
                ShowFormLogin();
            }
        }

        private void DisableMenuWithRoleTrainer()
        {
            tsmiAdministration.Enabled = false;
            tsmiAccount.Enabled = false;
            tsmiClass.Enabled = false;
            tsmiCourse.Enabled = false;
            tsmiFee.Enabled = false;
            tsmiRollcall.Enabled = false;
            tsmiStaffInfo.Enabled = false;
            tsmiStudentInfo.Enabled = false;
            tsmiReport.Enabled = false;
            tsmiSubject.Enabled = false;
            tsmiSubjectDetail.Enabled = false;
            tsmiStudentInformtion.Enabled = false;
        }

        private void EnableMenuWithRoleTrainer()
        {
            tsmiAdministration.Enabled = true;
            tsmiAccount.Enabled = true;
            tsmiClass.Enabled = true;
            tsmiCourse.Enabled = true;
            tsmiFee.Enabled = true;
            tsmiRollcall.Enabled = true;
            tsmiStaffInfo.Enabled = true;
            tsmiStudentInfo.Enabled = true;
            tsmiSubject.Enabled = true;
            tsmiSubjectDetail.Enabled = true;
            tsmiReport.Enabled = true;
            tsmiStudentInformtion.Enabled = true;
        }

        private void EnableMenuOfApplication()
        {
            tsmiAdministration.Enabled = true;
            tsmiManage.Enabled = true;
            tsmiReport.Enabled = true;
            tsmiStudentInformtion.Enabled = true;
            EnableMenuWithRoleTrainer();
        }

        private void InitializeMenuOfApplication()
        {
            switch (this.sRole)
            {
                case "R11":
                    {
                        tsmiStudentInformtion.Enabled = false;
                        break;
                    }
                case "R12":
                    {
                        tsmiAdministration.Enabled = false;
                        tsmiStudentInformtion.Enabled = false;
                        break;
                    }
                case "R13":
                    {
                        DisableMenuWithRoleTrainer();
                        break;
                    }
                case "R14":
                    {
                        tsmiAdministration.Enabled = false;
                        tsmiManage.Enabled = false;
                        tsmiReport.Enabled = false;
                        tsmiReport.Enabled = false;
                        break;
                    }
                default:
                    {
                        //tsmiAdministration.Enabled = false;
                        //tsmiManage.Enabled = false;
                        //tsmiReport.Enabled = false;
                        //tsmiStudentInformtion.Enabled = false;
                        break;
                    }
            }
        }
        private void FrmMain_Load(object sender, EventArgs e)
        {
            ShowFormLogin();
            InitializeMenuOfApplication();
            
        }

        private void tsmiLogin_Click(object sender, EventArgs e)
        {
            ShowFormLogin();
        }

        private void tsmiLogout_Click(object sender, EventArgs e)
        {
            ShowLogout();
        }

        private void tsmiChangePassword_Click(object sender, EventArgs e)
        {
            FrmChangePassword frmChangePassword = new FrmChangePassword();
            frmChangePassword.StartPosition = FormStartPosition.CenterParent;
            frmChangePassword.sLoginID = this.sLoginID;
            frmChangePassword.ShowDialog();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tsmiAccount_Click(object sender, EventArgs e)
        {
            FrmAccount frmAccount = new FrmAccount();
            frmAccount.StartPosition = FormStartPosition.CenterParent;
            frmAccount.ShowDialog();
        }

        private void tsmiCourse_Click(object sender, EventArgs e)
        {
            FrmCourse frmCourse = new FrmCourse();
            frmCourse.StartPosition = FormStartPosition.CenterParent;
            frmCourse.ShowDialog();
        }

        private void tsmiClass_Click(object sender, EventArgs e)
        {
            FrmClass frmClass = new FrmClass();
            frmClass.StartPosition = FormStartPosition.CenterParent;
            frmClass.ShowDialog();
        }

        private void subjectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmSubject frmSubject = new FrmSubject();
            frmSubject.StartPosition = FormStartPosition.CenterParent;
            frmSubject.ShowDialog();
        }

        private void tsmiStudentInfo_Click(object sender, EventArgs e)
        {
            FrmStudentInfo frmStudentInfo = new FrmStudentInfo();
            frmStudentInfo.StartPosition = FormStartPosition.CenterParent;
            frmStudentInfo.ShowDialog();
        }

        private void tsmiStaffInfo_Click(object sender, EventArgs e)
        {
            FrmStaffInfo frmStaffInfo = new FrmStaffInfo();
            frmStaffInfo.StartPosition = FormStartPosition.CenterParent;
            frmStaffInfo.ShowDialog();
        }

        private void tsmiMarks_Click(object sender, EventArgs e)
        {
            FrmMarks frmMarks = new FrmMarks();
            frmMarks.StartPosition = FormStartPosition.CenterParent;
            frmMarks.ShowDialog();
        }

        private void tsmiRollcall_Click(object sender, EventArgs e)
        {
            FrmRollcall frmRollcall = new FrmRollcall();
            frmRollcall.StartPosition = FormStartPosition.CenterParent;
            frmRollcall.ShowDialog();
        }

        private void tsmiFee_Click(object sender, EventArgs e)
        {
            FrmFee frmFee = new FrmFee();
            frmFee.StartPosition = FormStartPosition.CenterParent;
            frmFee.ShowDialog();
        }

        private void tsmiStudentInformtion_Click(object sender, EventArgs e)
        {
            FrmInformationAboutStudent frmInformationAboutStudent = new FrmInformationAboutStudent();
            frmInformationAboutStudent.StartPosition = FormStartPosition.CenterParent;
            frmInformationAboutStudent.sPersonID = this.sPersonID;
            frmInformationAboutStudent.ShowDialog();
        }

        private void subjectDetailToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmSubjectDetail frmSubjectDetail = new FrmSubjectDetail();
            frmSubjectDetail.StartPosition = FormStartPosition.CenterParent;
            frmSubjectDetail.ShowDialog();
        }

        private void listOfAttendanceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmListOfAttendanceReport frmReport = new FrmListOfAttendanceReport();
            frmReport.StartPosition = FormStartPosition.CenterParent;
            frmReport.ShowDialog();
        }

        private void warningReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmWarningReport frmWarningReport = new FrmWarningReport();
            frmWarningReport.StartPosition = FormStartPosition.CenterParent;
            frmWarningReport.ShowDialog();
        }

        private void marksOfStudentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmStudentMarksReport frmStudentMarksReport = new FrmStudentMarksReport();
            frmStudentMarksReport.StartPosition = FormStartPosition.CenterParent;
            frmStudentMarksReport.ShowDialog();
        }


    }
}